// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/equipment/api/AssetManageApi'
import EditClass from '@api/equipment/model/AssetBindDeviceReq'

import API from '@admin/views/Maintain/Device/DeviceList/store/API'

const RejClass = EditClass

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  ...API,

  // —————————————————————————————— 单项 —————————————————————————————— //

  validOne(one) {
    return one.id
  },
  transOne(obj) {
    const { deviceId, deviceName, deviceCode } = obj
    obj.device = { id: deviceId, deviceName, deviceCode } // 关联设备
    return obj
  },

  // —————————————————————————————— 修改 —————————————————————————————— //

  transEdit(one) {
    const { id: assetId, device: { id: deviceId, deviceName, deviceCode } } = one
    return { assetId, deviceId, deviceName, deviceCode }
  },
  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one)
    await CORE.grpc(TIP, CLIENT, 'assetBindDevice', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 拒绝 —————————————————————————————— //

  transRej(one) {
    const { id: assetId } = one
    return { assetId }
  },
  async rej(one, TIP = '拒绝') {
    const DTO = CORE.grpcDTO(RejClass, one)
    await CORE.grpc(TIP, CLIENT, 'assetBindDevice', DTO)
    return CORE.grpcOK(TIP)
  },
}
